package com.itheima.controller;

import com.itheima.domain.Product;
import com.itheima.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController {


    @Autowired
    private IProductService productService;
    //查询所有产品信息
    @RequestMapping("findAll.do")
    public ModelAndView findAll() {
        ModelAndView mv = new ModelAndView();
        List<Product> list = productService.findAll();
        mv.addObject("productList", list);
        mv.setViewName("product-list1");
        return mv;
    }

    //新增产品信息
    @RequestMapping("save.do")
    public String saveProduct(Product product) {
        productService.saveProduct(product);
        return "redirect:findAll.do";
    }

}
